import { request, ListData, SearchParamsData, WorkDataProps, baseAdminAPI } from '@/service/request'

export interface MonthlyDataProps {
  month: string
  data: {
    created: number
    published: number
  }
}

export async function fetchWorks(payload: SearchParamsData) {
  const rawData = await request<ListData<WorkDataProps>>(baseAdminAPI + '/works', 'get', payload)
  return rawData.data
}

// ids  '1' 或 '1,2,3'
export async function forceOffline(payload: { ids: string }) {
  await request(baseAdminAPI + '/works/forceOffline', 'post', payload)
}

export async function undoForceOffline(payload: { ids: string }) {
  await request(baseAdminAPI + '/works/undoForceOffline', 'post', payload)
}

export async function getCount() {
  const rawData = await request<{ created: number; published: number }>(baseAdminAPI + '/works/getCount', 'get')
  return rawData.data
}

export async function getMonthlyCount() {
  const rawData = await request<MonthlyDataProps[]>(baseAdminAPI + '/works/getMonthlyCount', 'get')
  return rawData.data
}
